import CONSTANT from '../../constant';

 export default function(poster) {
    
    // const rows = [];
    const netType = navigator.connection.type || '';
    const navigation = window.performance.getEntriesByType("navigation")[0];
    // 指标数据定义
    // 1.DNS查询耗时 ：domainLookupEnd - domainLookupStart
    // 2.TCP链接耗时 ：connectEnd - connectStart
    // 3.SSL安全连接耗时: connectEnd - secureConnectionStart
    // 4.request请求耗时 ：responseEnd - responseStart
    // 5.解析dom树耗时 ： domComplete - domInteractive
    // 6.首次渲染时间/白屏时间 ：responseStart - startTime
    // 7.domready时间 ：domContentLoadedEventEnd - startTime
    // 8.onload时间(总下载时间) ：duration
    const perfData = {
        navType: navigation.type, // 页面加载方式
        netType: netType,
        entryType: navigation.entryType,
        domainLookupEnd: navigation.domainLookupEnd,
        domainLookupStart: navigation.domainLookupStart,
        requestStart: navigation.requestStart,
        responseEnd: navigation.responseEnd,
        domComplete: navigation.domComplete,
        domInteractive: navigation.domInteractive,
        domContentLoadedEventStart: navigation.domContentLoadedEventStart,
        domContentLoadedEventEnd: navigation.domContentLoadedEventEnd,
        loadEventStart: navigation.loadEventStart,
        loadEventEnd: navigation.loadEventEnd,
        decodedBodySize: navigation.decodedBodySize,
        duration: navigation.duration,
        startTime: navigation.startTime,
    };

    perfData.uuid = CONSTANT.uuid;
    perfData.type = 'perf';
    // rows.push(perfData);

    // const resources = window.performance.getEntriesByType('resource');
    // let i = 0; const l = resources.length;
    // for (; i < l ; i++) {
    //     const item = resources[i];
    //     const row = {
    //         name: item.name,
    //         netType: netType,
    //         entryType: item.entryType,
    //         initiatorType: item.initiatorType,
    //         domainLookupEnd: item.domainLookupEnd,
    //         domainLookupStart: item.domainLookupStart,
    //         requestStart: item.requestStart,
    //         responseEnd: item.responseEnd,
    //         decodedBodySize: item.decodedBodySize,
    //         duration: item.duration,
    //         startTime: item.startTime,
    //         pathname: location.pathname,
    //         uuid: CONSTANT.uuid,
    //         type: 'perf',
    //     };

    //     rows.push(row);
    // }

    // return rows;

    poster.sendDataByImg(perfData);
 }